package com.zyong.encryption.server.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException;
import org.springframework.stereotype.Service;
import com.zyong.encryption.common.holder.LogUtil;
import com.zyong.encryption.server.secure.Base64Util;
import com.zyong.encryption.server.service.EncryptionService;

@Service
public class EncryptionServiceImpl implements EncryptionService {
    private static final Logger LOGGER = LoggerFactory.getLogger(EncryptionServiceImpl.class);

    @Override
    public String encode(String originContent) {
        try {
            return Base64Util.encode(originContent);
        } catch (UnsupportedEncodingException e) {
            LogUtil.error(LOGGER, "Encryption Error:{}", e :: getMessage);
        }
        return null;
    }

    @Override
    public String decode(String encryptionContent) {
        return Base64Util.decode(encryptionContent);
    }

}
